<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>

<body>
    <button id="btn">click</button>
    <script>
        const baseUrl = 'http://www.liulongbin.top:3006';

        let request = (url, method = 'get', data) => {
            let urls = baseUrl + url;
            return new Promise((resolve, reject) => {
                if (method == 'get' || method == 'delete') {
                    axios.get(urls, { params: data }).then(res => resolve(res.data))
                }
                if (method == 'post' || method == 'put') {
                    axios.post(urls, data).then(res => resolve(res.data))
                }
                else {
                    axios.options(urls, data).then(res => resolve(res.data))
                }

            })
        }

        let btn = document.getElementById('btn')
        btn.onclick = async function () {
            /*  let { data } = await request('/api/cmtlist')
             console.log(data) */

            let obj = {
                username: '法外狂徒',
                content: '张三不死 法律永存'
            };
            let postDate = await request('/api/addcmt', 'post', obj)
            console.log(postDate)

            console.log(await request('/api/cmtlist', 'get'))
        }
    </script>
</body>

</html>